package com.sgb.knowledgeshare.viewmodel;


import androidx.lifecycle.ViewModel;

import com.sgb.knowledgeshare.ShareConfig;
import com.sgb.knowledgeshare.entity.ShareDictEntity3;
import com.sgb.knowledgeshare.view.fragment.RecommendFragment;
import com.sgb.knowledgeshare.weight.ControllerView;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.VideoBean;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;
import com.swgk.core.view.entity.VideoListEntity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class RecommendModel extends ViewModel {
    RecommendFragment recommendfragment;
    private ArrayList<Long> delectList;

    public void setActivity(RecommendFragment recommendFragment) {
        recommendfragment = recommendFragment;
    }

//    获取所有视频数据信息
    public void getFirstPageList(String page,String type) {
        Map map = new HashMap();
        map.put("pageNum", page);//longitude
        map.put("pageSize", 10);
        map.put("type",type );
        DialogHelper.showProgressDialog(recommendfragment.getContext(), null, "加载中...", 0, true, null).setCanceledOnTouchOutside(false);
        ShareConfig.getInstance().getApi().getFirstPageList(map).enqueue(new ICallBack<BaseEntity<VideoListEntity>>() {
            @Override
            public void onSuccess(BaseEntity<VideoListEntity> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    recommendfragment.setListVideo(data.getData());
                }
            }
        });
    }

    //获取用户信息资料
    public void getMyVodList(int pageNum, String createUser, String videoId) {
        Map map = new HashMap();
        map.put("pageNum",pageNum);
        map.put("pageSize",10);
        map.put("userNo",createUser);
        map.put("videoId",videoId);
        map.put("type",0);
        DialogHelper.showProgressDialog(recommendfragment.getContext(), null, "加载中 ...", 0, true, null).setCanceledOnTouchOutside(false);
        ShareConfig.getInstance().getApi().getmyVodList(map).enqueue(new ICallBack<BaseEntity<VideoListEntity>>() {
            @Override
            public void onSuccess(BaseEntity<VideoListEntity> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    recommendfragment.setUserVideoListData(data.getData().getTotal(), data.getData());
                }
            }
        });
    }

    //点赞的操作
    public void setLike(String s) {
        Map map = new HashMap();
        map.put("videoId", s);//longitude
        ShareConfig.getInstance().getApi().getlike(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {

            }
        });
    }

    //删除视频
    public void deleteMyVideo(int id) {
        delectList = new ArrayList<>();
        delectList.add((long) id);
        DialogHelper.showProgressDialog(recommendfragment.getContext(), null, "删除中...", 0, true, null).setCanceledOnTouchOutside(false);
        ShareConfig.getInstance().getApi().getDeleteMyVideo(delectList).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    MToast.showToast(recommendfragment.getActivity(), "删除视频成功！");
                    recommendfragment.setDataList();
                }
            }
        });
    }

    /*
     * 点击+号关注的实现
     * */
    public void getFens(String userid) {
        Map map = new HashMap();
        map.put("userNo",userid );
        ShareConfig.getInstance().getApi().getfens(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {

            }
        });
    }

    //获取评论数量
    public void getCommentNum(VideoBean videoData, ControllerView controllerView) {
        Map map = new HashMap();
        map.put("videoId", videoData.getVideoId());//longitude
        ShareConfig.getInstance().getApi().getCommentCount(map).enqueue(new ICallBack<BaseEntity<ShareDictEntity3>>() {
            @Override
            public void onSuccess(BaseEntity<ShareDictEntity3> data) {
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    videoData.setCommentCount(Integer.parseInt(data.getData().getParam()));
                    recommendfragment.setCommentNum(videoData,controllerView);
                }
            }
        });
    }
    /*
     * 视频播放次数实现
     * */
    public void getplayVideo(String videoId) {
        Map map = new HashMap();
        map.put("videoId",videoId );
        ShareConfig.getInstance().getApi().getplayVideos(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {

            }
        });
    }


}
